#define datashowbox()
<style>
	.barchart {
		height: 520px;	
	}
	
	.changesel {
		overflow: hidden;
		margin: 9px 0 10px;
	}
	
	.changesel select {
	    width: 125px;
	    float: left;
	    margin-right: 15px;
	}
</style>
<div class="col-md-9" style="overflow: hidden;position: relative;" id="datashowbox">
	<div class="changesel">
		<select id="year" class="form-control">
			<option value="">选择年份</option>
		</select>
		<select id="month" class="form-control">
			<option value="">选择月份</option>
		</select>
	</div>
	<div class="barchart" id="ordernum_chart"></div>	
</div>
<script>
	$(function(){
		var account = "#(user.account)",//当前登录账号
			post = "#(post)",//账号权限
			accountCreateTime = "#(user.regTime)",//账号创建日期
			first_Index = accountCreateTime.indexOf("-"),//第一个-索引
			last_Index = accountCreateTime.lastIndexOf("-"),//最后一个-索引
			accountCreateTime_year = accountCreateTime.substring(0,first_Index),//获取创建年份
			accountCreateTime_month = accountCreateTime.substring(first_Index + 1,last_Index),//创建月份
			yearDom = $("#year"),
			monthDom = $("#month"),
			date = new Date(),
			nowYear = date.getFullYear(),
			nowMonth = date.getMonth() + 1,
			ordernum_chart = $("#ordernum_chart")[0],//业务数据统计
			orderChar = echarts.init(ordernum_chart);
		
		if(nowMonth < 10)nowMonth = "0" + nowMonth
		
		//只能查询创建日期之后的数据
		var account_monthArr = [parseInt(accountCreateTime_month),nowMonth]
		for(var i = accountCreateTime_year;i <= nowYear;i++){
			var pos = -1,
				selected = ""
			if(i == accountCreateTime_year){
				pos = 0
			}else if(i == nowYear){
				pos = 1
				selected = "selected='true'"
			}
				
			yearDom.append("<option value='"+ i +"|"+ pos +"' "+ selected +" year='"+ i +"'>"+ i +"</option>")
		}
		
		for(var i = 1;i <= nowMonth;i++){
			var m = i,
				selected = ""
			if(m < 10)m = "0" + m
			if(i == nowMonth)selected = "selected='true'"
			monthDom.append("<option value='"+ m +"' "+ selected +">"+ i +"月</option>")
		}
		
		var chartParams = {
			params: {
				tab: 'bargain_step,bargainReview_record,bargain_loan',
				param: post,
				datePara: 'reviewDate',
				dateRage: nowYear +'-'+ nowMonth,
				filter: 'bargainReview_record.assessor="'+ account +'" and bargainReview_record.post="'+ post +'" and bargainReview_record.order_id=bargain_step.order_id and bargain_loan.order_id=bargain_step.order_id'
			}
		}
		
		axios.get("/statis/getStatisByDate",chartParams)
		.then(function(res){
			console.log(res.data)
			var data = res.data,
				names = "",
				orderNum = [],//单量
				sucOrderNum = []//完成单量
			if(data.code == 1){
				names = data.names
				orderNum = data.orderNum
				sucOrderNum = data.data[post]["5"]
				var first_ = names[0].indexOf("-")	
			
				for(var i = 0;i < names.length;i++){
					names[i] = names[i].substring(first_ + 1)
				}
			}
			//默认显示当月1号到30号
			orderChar.setOption({
				title : {
			        text: '单量统计',
			        subtext: nowYear +"-"+ nowMonth,
			        textStyle: {
			       		fontWeight: 'normal',
			       		color: '#666'
			        }
			    },
			    color:["#0099FF","#5cb85c"],
			    tooltip : {
			        trigger: 'axis'
			    },
			    legend: {
			        data:['总单量','完成单量']
			    },
			    toolbox: {
			        show : true,
			        feature : {
			        	dataView : {show: true, readOnly: false},
			        	magicType : {show: true, type: ['line', 'bar']},
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
			    calculable : true,
			    xAxis : [
			        {
			            type : 'category',
			            'axisLabel':{'interval':0},
			            data : names
			        }
			    ],
			    yAxis : [
			        {
			            type : 'value'
			        }
			    ],
			    grid: {
			        left: '0',
			        right: '2.8%',
			        bottom: '0',
			        containLabel: true
			    },
			    series : [
			        {
			            name:'总单量',
			            type:'bar',
			            data:orderNum,
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            }
			        },
			        {
			            name:'完成单量',
			            type:'bar',
			            data:sucOrderNum,
			            markPoint : {
			            	data : [
			                    {type : 'max', name: '最大值'},
			                    {type : 'min', name: '最小值'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name : '平均值'}
			                ]
			            }
			        }
			        
			    ]
			})
		})
		
		yearDom.change(function(){
			var val = $(this).val()
			if(val != ""){
				var arr = val.split("|"),
					year = arr[0],
					pos = arr[1]
				monthDom.val("")
				getOrderData(year,"year")
				monthDom.html("<option value=''>选择月份</option>")
				if(pos == 0){
					for(var i = account_monthArr[pos];i <= 12;i++){
						var m = i
						if(m < 10)m = "0" + m
						monthDom.append("<option value='"+ m +"'>"+ i +"月</option>")
					}
				}else if(pos == 1){
					for(var i = 1;i <= account_monthArr[pos];i++){
						var m = i
						if(m < 10)m = "0" + m
						monthDom.append("<option value='"+ m +"'>"+ i +"月</option>")
					}
				}else if(pos == -1){
					for(var i = 1;i <= 12;i++){
						var m = i
						if(m < 10)m = "0" + m
						monthDom.append("<option value='"+ m +"'>"+ i +"月</option>")
					}
				}
			}else{
				monthDom.html("<option value=''>选择月份</option>")
			}
		})
		
		monthDom.change(function(){
			var year = yearDom.val().split("|")[0],
				month = $(this).val()
				date = year+"-"+month
			if(month == "")date = year
			getOrderData(date,"month")
		})
		
		function getOrderData(date,filter){
			chartParams.params.dateRage = date
			var subtext = yearDom.val().split("|")[0]
			if(monthDom.val() != ""){
				subtext = subtext +"-"+ monthDom.val()
			}
			
			axios.get("/statis/getStatisByDate",chartParams)
			.then(function(res){
				var data = res.data,
					names = [],
					orderNum = [],//单量
					sucOrderNum = []//完成单量
				
				if(data.code == 1){
					names = data.names
					if(filter == "month"){
						orderNum = data.orderNum
						sucOrderNum = data.data[post]["5"]
						if(date.indexOf("-") != -1){
							var first_ = names[0].indexOf("-")	
							for(var i = 0;i < names.length;i++){
								names[i] = names[i].substring(first_ + 1)
							}
						}
					}else{
						orderNum = data.orderNum
						sucOrderNum = data.data[post]["5"]
					}
				}else{
					//数据没有就模拟数据
					if(filter == "year"){
						var pos = yearDom.find("option[year='"+ subtext +"']").attr("value").split("|")[1]
						if(pos == 0){
							for(var i = account_monthArr[pos];i <= 12;i++){
								var m = i
								if(m < 10)m = "0" + m
								names.push(subtext +"-"+ m)
								orderNum.push(0)
								sucOrderNum.push(0)
							}
						}else if(pos == 1){
							for(var i = 1;i <= account_monthArr[pos];i++){
								var m = i
								if(m < 10)m = "0" + m
								names.push(subtext +"-"+ m)
								orderNum.push(0)
								sucOrderNum.push(0)
							}
						}else if(pos == -1){
							for(var i = 1;i <= 12;i++){
								var m = i
								if(m < 10)m = "0" + m
								names.push(subtext +"-"+ m)
								orderNum.push(0)
								sucOrderNum.push(0)
							}
						}
					}else{
						if(date.indexOf("-") != -1){
							var year = date.split("-")[0],
								month = date.split("-")[1],
								days = new Date(year,month,0).getDate()
							for(var i = 1;i <= days;i++){
								var m = i
								if(m < 10)m = "0" + m
								if(i % 2 == 0){
									names.push("\n" + month +"-"+ m)
								}else{
									names.push(month +"-"+ m)
								}
								orderNum.push(0)
								sucOrderNum.push(0)
							}
						}else{
							var pos = yearDom.find("option[year='"+ date +"']").attr("value").split("|")[1]
							if(pos == 0){
								for(var i = account_monthArr[pos];i <= 12;i++){
									var m = i
									if(m < 10)m = "0" + m
									names.push(subtext +"-"+ m)
									orderNum.push(0)
									sucOrderNum.push(0)
								}
							}else if(pos == 1){
								for(var i = 1;i <= account_monthArr[pos];i++){
									var m = i
									if(m < 10)m = "0" + m
									names.push(subtext +"-"+ m)
									orderNum.push(0)
									sucOrderNum.push(0)
								}
							}else if(pos == -1){
								for(var i = 1;i <= 12;i++){
									var m = i
									if(m < 10)m = "0" + m
									names.push(subtext +"-"+ m)
									orderNum.push(0)
									sucOrderNum.push(0)
								}
							}
						}
					}
				}
				
				orderChar.setOption({
					title : {
				        subtext: subtext
				    },
				    xAxis : [
				        {
				            data : names
				        }
				    ],
				    series : [
				        {
				            name:'总单量',
				            type:'bar',
				            data:orderNum,
				            markPoint : {
				                data : [
				                    {type : 'max', name: '最大值'},
				                    {type : 'min', name: '最小值'}
				                ]
				            },
				            markLine : {
				                data : [
				                    {type : 'average', name: '平均值'}
				                ]
				            }
				        },
				        {
				            name:'完成单量',
				            type:'bar',
				            data:sucOrderNum,
				            markPoint : {
				            	data : [
				                    {type : 'max', name: '最大值'},
				                    {type : 'min', name: '最小值'}
				                ]
				            },
				            markLine : {
				                data : [
				                    {type : 'average', name : '平均值'}
				                ]
				            }
				        }
				        
				    ]
				})
			})
		}
		
		window.onresize = function(){
			orderChar.resize()
		}
		
	})
</script>
#end